import React, {
  useState,
  useEffect,
  useMemo,
  useReducer,
  useContext,
} from "react";
// import { StyleSheet, Text, View, Button, ScrollView, Easing, ActivityIndicator } from 'react-native';

import "react-native-gesture-handler";

import { NavigationContainer } from "@react-navigation/native";
import { createDrawerNavigator } from "@react-navigation/drawer";
import { createNativeStackNavigator } from "@react-navigation/native-stack";

import { Provider, useSelector } from "react-redux";
import { store } from "./src/store/index";

import { Provider as AuthProvider } from "./src/context/AuthContext";
import { MaterialProvider } from "./src/context/suppiler/materialContext";

import { navigationRef } from "./src/RootNavigation";
import LoginStackScreen from "./src/screens/LoginStackScreen";
import MainTabScreen from "./src/screens/MainTabScreen";
import SupportScreen from "./src/screens/SupportScreen";
import SettingScreen from "./src/screens/SettingScreen";
import { DrawerContent } from "./src/screens/DrawerContent";
import Admin from "./src/screens/admin";

import SupplierNavigation from "./src/navigation/SupplierNavigation";

const Drawer = createDrawerNavigator();
const Stack = createNativeStackNavigator();

const DrawerNav = () => {
  return (
    <Drawer.Navigator drawerContent={(props) => <DrawerContent {...props} />}>
      <Drawer.Screen
        name="HomeDrawer"
        component={MainTabScreen}
        options={{ headerShown: false, gestureEnabled: true }}
      />
      {/* <Drawer.Screen name="Support" component={SupportScreen} />
      <Drawer.Screen name="Setting" component={SettingScreen} /> */}
    </Drawer.Navigator>
  );
};

const RootNavigation = () => {
  const aauthToken = useSelector((state) => state.authR.authToken);
  const aauthRole = useSelector((state) => state.authR.authRole);
  console.log(aauthToken);
  const home =
    aauthRole == "supplier" ? (
      <Stack.Navigator>
        {/* <Stack.Screen
          name="Admin"
          component={Admin}
          options={{ headerShown: false }}
        ></Stack.Screen> */}
        <Stack.Screen
          name="Admin"
          component={SupplierNavigation}
          options={{ headerShown: false }}
        ></Stack.Screen>
      </Stack.Navigator>
    ) : (
      <DrawerNav />
    );
  return (
    <NavigationContainer ref={navigationRef}>
      {aauthToken != null ? home : <LoginStackScreen />}
      {/* <DrawerNav /> */}
    </NavigationContainer>
  );
};

export default function App() {
  return (
    <Provider store={store}>
      <AuthProvider>
        <MaterialProvider>
          <RootNavigation />
        </MaterialProvider>
      </AuthProvider>
    </Provider>
  );
}
